import java.util.ArrayList;
import java.util.List;

public class Student {
    private final String studentId;   // 学生编号
    private final String name;        // 学生姓名
    private final List<Course> selectedCourses; // 所选课程列表

    // 构造方法
    public Student(String studentId, String name) {
        this.studentId = studentId;
        this.name = name;
        this.selectedCourses = new ArrayList<>();
    }

    // 选课
    public void selectCourse(Course course) {
        if (course != null && !selectedCourses.contains(course)) {
            selectedCourses.add(course);
            System.out.println(name + "成功选修课程: " + course.getCourseName());
        } else {
            System.out.println(name + "选修课程失败，课程不存在或已选");
        }
    }

    // 退课
    public void dropCourse(Course course) {
        if (course != null && selectedCourses.contains(course)) {
            selectedCourses.remove(course);
            System.out.println(name + "成功退选课程: " + course.getCourseName());
        } else {
            System.out.println(name + "退选课程失败，课程不存在或未选");
        }
    }

    // 打印课表
    public void printSchedule() {
        System.out.println("\n" + name + "的课表（学号: " + studentId + "）:");
        if (selectedCourses.isEmpty()) {
            System.out.println("未选任何课程");
            return;
        }

        System.out.println("------------------------------------------------");
        System.out.printf("%-10s %-15s %-10s %-15s %-10s%n",
                "课程编号", "课程名称", "地点", "时间", "教师");
        System.out.println("------------------------------------------------");

        for (Course course : selectedCourses) {
            System.out.printf("%-10s %-15s %-10s %-15s %-10s%n",
                    course.getCourseId(),
                    course.getCourseName(),
                    course.getLocation(),
                    course.getTime(),
                    course.getTeacher().getName());
        }
        System.out.println("------------------------------------------------");
    }

}
